﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Documents;
using System.Printing;
namespace ITXHWEB.Controllers
{
    public partial class WBDATXController : ITXController
    {
        
        [ChildActionOnly]
        public ActionResult PSHWB04(string returnUrl)
        {
            ModelState.Clear(); 
            AUTOCHK();
             ViewBag.ReturnUrl = returnUrl;
            return PartialView();
        }

        public void AUTOCHK()
        {
            if (MABF == null)
                return;
            if (MABF.ABPAUF.Length<10)
                return;
            if (MABF.MABP==null)
                return;
            if (!MABF.IsEXORDReady)
                return;
            dwData = VHP.VWB.TBMain.NewRow();
            dwData["WBMANDANT"] = app.Mandant;
            dwData["WBBESTKZ"] ="V";
            dwData["WBBESTKRS"] = MABF.KRS;
            dwData["WBBESTLFD"] = MABF.LFD;
            dwData["WBBESTPOS"] = MABF.POS;
            SResult = VHP.VWB.QWBDAT02(dwData);
            String WB04KEY = "";
            foreach(DataRow row in SResult.Tables[0].Rows)
            {
                WB04KEY= row["WBRWKRS"].ToString() + row["WBRWLFD"].ToString();
            }
            PM["dwABP"] = MABF.MABP.dwABP;
            PM["IsAppend"] = true;
            PM["WB04KEY"] = WB04KEY;
            PM["CUSER"] = CUSER;
            PM["IsClear"] =false;
            PM["LOOMID"] = MABF.MACHINEID;

            DataRow dwWBB =VHP.VWB.APPENDWB61(PM); 
            MABF.CWBB.RWKRS= dwWBB["WBBRWKRS"].ToString();
            MABF.CWBB.RWLFD = dwWBB["WBBRWLFD"].ToString();
            MABF.CWBB.RWPOS = dwWBB["WBBPOS"].ToString();
            MABF.CWBB.WBBSTKNR = dwWBB["WBBSTKNR"].ToString();             
         }
    }
}
